package com.example.psychologicalappointmentsystem.tools;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * ClassName DateTools
 * Description TODO
 * Date 2025/2/11 17:53
 * Version 1.0
 */
public class DateTools {
    //将LocalDate 转为Date
    public static Date convertToLocalDateAsDate(LocalDateTime localDateTime) {
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }
    //将Date 转为LocalDate
    public static LocalDateTime convertToDateLocalDateTime(Date date) {
        // 首先将Date转换为Instant
        Instant instant = date.toInstant();

        // 然后使用系统默认时区将Instant转换为LocalDateTime
        return instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
    }

}
